home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / Build_Index.ieb < prev    next >
Encoding:
Text File  |  1997-02-02  |  5.1 KB  |  186 lines

  1. /*
  2. ** $VER: Build_Index.ieb 1.3, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten
  5. ** 2/2 1997 Stockholm/Sweden
  6. **
  7. ** Outputs only one single image containing thumbnail images
  8. ** of all selected PRIMARY images.
  9. */
  10.  
  11. options results
  12. signal on error
  13.  
  14. parse arg input command
  15. input = upper(strip(input))
  16. address 'IMAGEENGINEER'
  17.  
  18. select  /* Required batch script commands */
  19.   when input = 'INFO' then    return get_info()
  20.   when input = 'CONFIG' then  return get_config(command)
  21.   when input = 'PROCESS' then return process_image(command)
  22.   otherwise do
  23.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  24.     return '<ERROR>'
  25.   end
  26. end
  27.  
  28. exit 0
  29.  
  30. /* Required "Get_info" procedure  ------------------------------------ */
  31. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  32.  
  33. get_info:
  34.   back = 'OK F'
  35. return back
  36.  
  37. /* Required "Get_config" procedure  ---------------------------------- */
  38.  
  39. get_config:
  40.   parse arg command
  41.  
  42.   'IE_TO_FRONT'
  43.  
  44.   /* Unchanged config, only picked for first image */
  45.  
  46.   if command = '' then do
  47.     'FORM "Build Index" " OK | Cancel "',
  48.     ' INTEGER,"Number of horiz. thumbnails",1,64,10,SLIDER',
  49.     ' INTEGER,"Thumbnail X size",16,320,64,SLIDER',
  50.     ' INTEGER,"Thumbnail Y size",16,256,64,SLIDER',
  51.     ' STRING,"Output base name","Output"',
  52.     ' CHECKBOX,"Keep image aspect in thumbnails?",1'
  53.  
  54.     parse var result ok Thumb Xsize Ysize '"'Base'"' Aspect .
  55.     if ok = 0 then return '<ERROR>'
  56.   end
  57.   else do
  58.     'REQUEST' '"The Build_Index.ieb does only have'd2c(10)||,
  59.               'settings for the first image."' '" OK "'
  60.     Thumb = 'none'
  61.     Xsize = 'none'
  62.     Ysize = 'none'
  63.     Base = 'none'
  64.     Aspect = 'none'
  65.   end
  66.  
  67.   Base = translate(Base,'ª',' ')
  68.  
  69.   back = '#'Thumb '#'Xsize '#'Ysize '#'Base '#'Aspect
  70. return back
  71.  
  72. /* Required "Process_image" procedure  ------------------------------- */
  73.  
  74. process_image:
  75.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"' '"'frame':'num_frames'"'
  76.   parse var options '#'Thumb '#'Xsize '#'Ysize '#'Base '#'Aspect .
  77.  
  78.   'OPEN' '"'src_image'"' '24'
  79.   if (RC ~= 0) then do
  80.     'IE_TO_FRONT'
  81.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  82.     return '<ERROR>'
  83.   end
  84.   else LoadImage = result
  85.  
  86.   if Thumb > num_frames then Thumb = num_frames
  87.  
  88.   if frame = 1 then do  /* Do only for first image */
  89.     'BRIGHTNESS' LoadImage '-255'
  90.     BlackImage = Result
  91.  
  92.     if (num_frames/Thumb) = trunc(num_frames/Thumb) then 'RESIZE' BlackImage (Thumb*Xsize) (Ysize*trunc(num_frames/Thumb))
  93.     else 'RESIZE' BlackImage (Thumb*Xsize) (Ysize*trunc(1+num_frames/Thumb))
  94.     BackImage = Result
  95.     'CLOSE' BlackImage
  96.   end
  97.   else do  /* Check for last ALPHA image */
  98.     'GET' 'ALPHA'
  99.     BackImage = Result
  100.   end
  101.  
  102.   'PROJECT_INFO' LoadImage 'WIDTH'
  103.   IW = RESULT
  104.   'PROJECT_INFO' LoadImage 'HEIGHT'
  105.   IH = RESULT
  106.  
  107.   if (Xsize ~= IW)|(Ysize ~= IH) then do
  108.     if Aspect = 1 then do  /* Aspect scale */
  109.       if ((Xsize/IW) > (Ysize/IH)) then ,
  110.            'SCALE' LoadImage trunc(IW*Ysize/IH) Ysize 'BEST'
  111.       else 'SCALE' LoadImage Xsize trunc(IH*Xsize/IW) 'BEST'
  112.       ThumbImage = Result
  113.       'CLOSE' LoadImage
  114.     end
  115.     else do  /* Stretch scale */
  116.       'SCALE' LoadImage Xsize Ysize 'BEST'
  117.       ThumbImage = Result
  118.       'CLOSE' LoadImage
  119.     end
  120.   end
  121.   else ThumbImage = LoadImage
  122.  
  123.   col = frame ; row = 1
  124.   do while (col > Thumb)
  125.     col = col - Thumb
  126.     row = row + 1
  127.   end
  128.  
  129.   'MARK' ThumbImage 'PRIMARY'
  130.   'MARK' BackImage 'SECONDARY'
  131.  
  132.   'COMPOSITE' (Xsize*(col-1)) (Ysize*(row-1))  'MIX' 100
  133.   NewBackImage = Result
  134.   'CLOSE' BackImage
  135.   'CLOSE' ThumbImage
  136.   BackImage = NewBackImage
  137.  
  138.   'MARK' BackImage 'ALPHA'  /* Mark as ALPHA to remember it to next load */
  139.  
  140.   if frame = num_frames then do  /* Only for last image */
  141.  
  142.     OutputImage = BackImage
  143.     Base = translate(Base,' ','ª')
  144.     dst_image = get_path(dst_image)||Base'.index'
  145.  
  146.     if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1')
  147.     'SAVE_DATA' OutputImage '"'dst_image'"' '"'getclip('cfg_save_frmt')'"'
  148.     if (RC ~= 0) then do
  149.       'IE_TO_FRONT'
  150.       'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "'
  151.       return '<ERROR>'
  152.     end
  153.     'CLOSE' OutputImage
  154.   end
  155.  
  156.   back = 'OK'
  157. return back
  158.  
  159. /* Internal procedures  ---------------------------------------------- */
  160.  
  161. get_path:
  162.   parse arg get_path_in
  163.   if lastpos('/',get_path_in) ~= 0 then get_path_back = substr(get_path_in,1,lastpos('/',get_path_in))
  164.   else if lastpos(':',get_path_in) ~= 0 then get_path_back = substr(get_path_in,1,lastpos(':',get_path_in))
  165.   else get_path_back = ''
  166. return get_path_back
  167.  
  168. /*******************************************************************/
  169. /* This is where control goes when an error code is returned by IE */
  170. /* It puts up a message saying what happened and on which line     */
  171. /*******************************************************************/
  172.  
  173. error:
  174. if RC=5 then do
  175.     IE_TO_FRONT
  176.     LAST_ERROR
  177.     'REQUEST "'||RESULT||'"'
  178. end
  179. else do
  180.     IE_TO_FRONT
  181.     LAST_ERROR
  182.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  183. end
  184.  
  185. return '<ERROR>'
  186.